class Solution(object):
    def productExceptSelf(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """
        res = [1] * len(nums)
        # print('start res is {}'.format(res))

        left = 1
        for i in range(len(nums) - 1):
            left *= nums[i]
            # print('left is {}'.format(left))
            res[i + 1] *= left
        # print('After left res is {}'.format(res))

        right = 1
        for i in range(len(nums) - 1, 0, -1):
            right *= nums[i]
            # print('right is {}'.format(right))
            res[i - 1] *= right
        # print('After right res is {}'.format(res))

        return res